/*  Novelties: A visual novel programming language based on JavaFX
    Copyright (C) 2008  Hao Xu

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * /
 /*
 * PictureBox.fx
 *
 * Created on Apr 6, 2008, 7:07:19 PM
 */

package avgengine;

import javafx.ui.canvas.*;
import javafx.ui.*;
import java.lang.Thread;
import avgengine.layout.*;

/**
 * @author ertri
 */

class Picture extends Dialog {
    attribute min:int*;
    attribute image:Image;
    operation setImage(img:Image);
    operation clearImageAndDo(o:operation());
    operation clearImageAndMinimize();
    operation xxx();
    operation replacePicture(img:Image);
}

attribute Picture.borderColor = blue;
attribute Picture.borderWidth = 2;
attribute Picture.arc = 10;
attribute Picture.speed = 500;
attribute Picture.dopacity = .5;
attribute Picture.pad = [10, 10];
attribute Picture.min = [10, 10];
attribute Picture.layoutManager = FullLayout{};

operation Picture.setImage(img) {
    this.image = img;
    this.clearImageAndDo(
    operation() {
        
        appendText(PictureParagraph{
            topacity : 1
            image:img,
            height:img.getImage().getHeight(null)
        });
        var w = img.getImage().getWidth(null);
        var h = img.getImage().getHeight(null);
        resize(w+2*pad[1],h+2*pad[0]);
    }
    );
    
}

operation Picture.clearImageAndDo(o) {
    this.image = null;
    this.clearTextAndDo(o);
}

operation Picture.clearImageAndMinimize() {
    resize(min[0], min[1]);
    this.clearText();
    this.image = null;
}

operation Picture.replacePicture(img) {
    this.image = img;
    
    var p = PictureParagraph{
        topacity : 1
        image:img,
    };
    
    this.replaceText(p);
    
    var w = img.getImage().getWidth(null);
    var h = img.getImage().getHeight(null);
    resize(w+2*pad[1],h+2*pad[0]);
}

var picture = Picture{};
LayoutManager{};

//Frame {
//    content:FlowPanel{
//        content:[
//        Canvas{content:picture},
//        Button{
//            text:"Add Picture",
//            action:operation() {
//                picture.setImage(Image{url: "Chi2.jpg"});
//            }
//        },
//        Button{
//            text:"Clear",
//            action:operation() {
//                picture.clearImageAndMinimize();
//            }
//        }]
//    }
//    visible:true
//}